package com.douyu.ocean.recom.platfrom.core.utils;

import javax.sql.DataSource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.douyu.ocean.datasource.spring.JdbcDataSource;



/**
 * Created final by luohao on 2016/12/12.
 */
public final class DataSourceUtils {
    private static final Logger logger = LoggerFactory.getLogger(DataSourceUtils.class);
    private DataSourceUtils() {
    }

    public static DataSource getDateSource(String url, String driver){
        try {
            JdbcDataSource dataSource = new JdbcDataSource();
            dataSource.setUrl(url);
            dataSource.setDriverClassName(driver);
            dataSource.setTestOnBorrow(true);
            dataSource.setTestWhileIdle(true);
            dataSource.setValidationQuery("select 1");
            dataSource.setValidationQueryTimeout(3);
            return dataSource;
        } catch (Exception e) {
            logger.error(e.getMessage(),e);
            return null;
        }
    }
}
